package com.huanzhidadi.single.enums;

public class WeekdayEnumTest {
    public static void main(String[] args) {

        System.out.println(Weekday.MON.name());
        System.out.println(Weekday.MON.ordinal());
        System.out.println(Weekday.MON.getValue());
        System.out.println(Weekday.MON.getLabel());
        System.out.println(Weekday.getNextDay(Weekday.SAT));
        System.out.println(Weekday.getWeekdayByValue(5));

        System.out.println("************************");
        System.out.println(Weekday.valueOf("mon".toUpperCase()));
        for (Weekday w : Weekday.values()){
            System.out.println(w + ".ordinal()  ====>" +w.ordinal());
        }
    }

}

enum Weekday {
    MON(1, "mon"),
    TUS(2, "tus"),
    WED(3, "wed"),
    THU(4, "thu"),
    FRI(5, "fri"),
    SAT(6, "sat"),
    SUN(0, "sun");

    // 自定义变量
    private int value;

    private String label;

    private Weekday(int value, String label) {
        this.value = value;
        this.label = label;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public static Weekday getNextDay(Weekday nowDay){
        int nextDayValue = nowDay.value;

        if (++nextDayValue == 7){
            nextDayValue = 0;
        }

        return getWeekdayByValue(nextDayValue);
    }

    public static Weekday getWeekdayByValue(int value) {
        for (Weekday c : Weekday.values()) {
            if (c.value == value) {
                return c;
            }
        }
        return null;
    }
}